package com.jbp.utils;

public class LevelUtil {
    //每个等级对应的总经验值
    private static int[] scores = {0, 1000, 2000, 3000, 4000, 5000, 7000, 9000, 11000, 13000, 15000, 20000, 25000, 30000, 35000, 40000,
            50000, 60000, 70000, 80000, 90000, 110000, 130000, 150000, 170000, 190000, 240000, 290000, 340000, 390000,
            440000, 540000, 640000, 740000, 840000, 940000, 1140000, 1340000, 1540000, 1740000, 1940000,
            2440000, 2940000, 3440000, 3940000, 4440000, 5440000, 6440000, 7440000, 8440000, 9440000, 11440000,
            13440000, 15440000, 17440000, 19440000, 23440000, 27440000, 31440000, 35440000, 39440000, 46440000, 53440000,
            60440000, 67440000, 74440000, 85440000, 96440000, 107440000, 118440000, 129440000, 145440000, 161440000,
            177440000, 193440000, 209440000, 231440000, 253440000, 275440000, 297440000, 319440000,
            359440000, 399440000, 439440000, 479440000,519440000,
            619440000, 719440000, 819440000, 919440000, 1019440000};

    /**
     * 根据经验值计算等级
     * @param experience 经验值
     * @return
     */
    public static int getLevel(int experience) {
        int level = 0;
        for (int i = 0; i < scores.length; i++) {
            if (experience >= scores[i]) {
                level = i;
            } else {
                break;
            }
        }
        return level;
    }

    public static int getExperByLevel(int level) {
        return scores[level];
    }
}
